package com.redoor.iot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.redoor.iot.aspect.Log;
import com.redoor.iot.model.Result;
import com.redoor.iot.model.Role;
import com.redoor.iot.service.IRoleService;
import com.redoor.iot.utils.ResultUtil;

@RestController
@RequestMapping(value="/role")
public class RoleController extends BaseController {
	
	@Autowired
	private IRoleService roleService;
	
	
	/*@RequiresPermissions("sys:role:role")
	@GetMapping("/list")
	@ResponseBody()
	List<RoleDO> list() {
		List<RoleDO> roles = roleService.list();
		return roles;
	}*/
	
	@Log("保存角色")
	/*@RequiresPermissions("sys:role:add")*/
	@PostMapping("/save")
	@ResponseBody()
	Result save(@Validated Role role,BindingResult bindingResult) {
		if(bindingResult.hasErrors()) {
			return ResultUtil.error(1, bindingResult.getFieldError().getDefaultMessage());
		} 
		role.setStatus(0);    //状态(0:有效;1:无效)
		if (roleService.save(role) > 0) {
			return ResultUtil.success();
		} else {
			return ResultUtil.error(1, "保存失败");
		}
	}
}
